package info.androidhive.actionbar;

import java.util.*;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class LocationSelection extends Activity
{
  ExpandableListAdapter listAdapter;
  ExpandableListView expListView;
  List<String> listDataHeader;
  HashMap<String, List<String>> listDataChild;
   
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_main);
    
    expListView = (ExpandableListView) findViewById(R.id.lvExp);
    prepareListData();
    
    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
    
    expListView.setAdapter(listAdapter);
    

    
    // Listview Group expanded listener
    expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

        @Override
        public void onGroupExpand(int groupPosition) {
//            Toast.makeText(getApplicationContext(),
//                    listDataHeader.get(groupPosition) + " Expanded",
//                    Toast.LENGTH_SHORT).show();
        }
    });

    // Listview Group collasped listener
    expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

        @Override
        public void onGroupCollapse(int groupPosition) {
//            Toast.makeText(getApplicationContext(),
//                    listDataHeader.get(groupPosition) + " Collapsed",
//                    Toast.LENGTH_SHORT).show();

        }
    });

    // Listview on child click listener
    expListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            // TODO Auto-generated method stub
            Toast.makeText(
                    getApplicationContext(),
                    listDataHeader.get(groupPosition)
                            + " : "
                            + listDataChild.get(
                                    listDataHeader.get(groupPosition)).get(
                                    childPosition), Toast.LENGTH_SHORT)
                    .show();
            return false;
        }
    });
    
  }
  
  public void prepareListData()
  {
    listDataHeader = new ArrayList<String> ();
    listDataChild = new HashMap<String, List<String>> ();
    
    listDataHeader.add("서울");
    listDataHeader.add("경기, 인천");
    listDataHeader.add("경상");
    listDataHeader.add("전라");
    listDataHeader.add("강원");
    listDataHeader.add("제주");
    
    List<String> seoul = new ArrayList<String> ();
    seoul.add("종로, 성북, 동대문, 성동, 중구");
    seoul.add("강북, 광진, 노원, 도봉, 중랑구");
    seoul.add("강남, 강동, 동작, 송파, 서초구");
    seoul.add("강서, 구로, 관악, 영등포, 양천, 금천구");
    seoul.add("서대문, 마포, 용산, 은평구");
    
    List<String> gyeonggi = new ArrayList<String> ();
    gyeonggi.add("인천");
    gyeonggi.add("고양, 김포");
    gyeonggi.add("성남, 용인, 광주");
    gyeonggi.add("수원, 화성, 안성");
    gyeonggi.add("광명, 부천, 하남");
    gyeonggi.add("안양, 과천, 평택");
    gyeonggi.add("구리, 남양주, 오산");
    gyeonggi.add("이천, 파주, 포천");
    gyeonggi.add("여주, 의왕, 군포, 양주");
    gyeonggi.add("가평, 양평, 연천");
    
    List<String> gyeongsang = new ArrayList<String> ();
    gyeongsang.add("대구");
    gyeongsang.add("부산");
    gyeongsang.add("경북");
    gyeongsang.add("경님");
    
    List<String> jeolla = new ArrayList<String> ();
    jeolla.add("광주");
    jeolla.add("전북");
    jeolla.add("전남");

    List<String> gangwon = new ArrayList<String> ();
    gangwon.add("강릉, 속초, 동해");
    gangwon.add("원주, 평창");
    gangwon.add("기타");

    List<String> jeju = new ArrayList<String> ();
    jeju.add("제주시");
    jeju.add("서귀포시");
    
    listDataChild.put(listDataHeader.get(0), seoul);
    listDataChild.put(listDataHeader.get(1), gyeonggi);
    listDataChild.put(listDataHeader.get(2), gyeongsang);
    listDataChild.put(listDataHeader.get(3), jeolla);
    listDataChild.put(listDataHeader.get(4), gangwon);
    listDataChild.put(listDataHeader.get(5), jeju);
  }
}
